//
//  CALayer+HBCategory.m
//  HBLibary
//
//  Created by Rambo on 2018/10/26.
//

#import "CALayer+HBCategory.h"

@implementation CALayer (HBCategory)

+ (instancetype)hb_layerWithLeftColor:(UIColor*)leftColor rightColor:(UIColor*)rightColor frame:(CGRect)frame{
    if (!leftColor) {
        leftColor = [UIColor clearColor];
    }
    
    if (!rightColor) {
        rightColor = [UIColor clearColor];
    }
    
    CAGradientLayer *layer = [CAGradientLayer layer];
    layer.colors = @[(__bridge id)leftColor.CGColor, (__bridge id)rightColor.CGColor];
    layer.startPoint = CGPointMake(0, 0);
    layer.endPoint = CGPointMake(1, 0);
    layer.frame = frame;
    
    return layer;
}

+ (instancetype)hb_layerWithTopColor:(UIColor*)topColor bottomColor:(UIColor*)bottomColor frame:(CGRect)frame{
    if (!topColor) {
        topColor = [UIColor clearColor];
    }
    
    if (!bottomColor) {
        bottomColor = [UIColor clearColor];
    }
    
    CAGradientLayer *layer = [CAGradientLayer layer];
    layer.colors = @[(__bridge id)topColor.CGColor, (__bridge id)bottomColor.CGColor];
    layer.startPoint = CGPointMake(0, 0);
    layer.endPoint = CGPointMake(0, 1);
    layer.frame = frame;
    
    return layer;
}


@end
